package com.zemb.flxwear.Utils;

import android.content.Context;
import android.content.res.Resources;

import com.zemb.flxwear.R;

import java.io.Serializable;

public class DeviceUtils {

    //血压
    public static final String BLOOD_PRESSURE = "FLX";
    //血氧
    public static final String BLOOD_OXYGEN = "Samo4";
    //血糖
    public static final String BLOOD_FOUR_CATEGORY = "BLE";
    //心电
    public static final String ECG = "H23";

    public static final String UUID="_uuid";
    public static final String SERVICE="_service";
    public static final String CHARACTERISTIC="_characteristic";


    public static String getDeviceName(Category category){
        switch (category){
            case BLOOD_PRESSURE:
                return BLOOD_PRESSURE;
            case BLOOD_OXYGEN:
                return BLOOD_OXYGEN;
            case BLOOD_SUGAR:
            case CHOLESTEROL:
            case BLOOD_KETONE:
            case URIC_ACID:
                return BLOOD_FOUR_CATEGORY;
            case ECG:
                return ECG;
            default:
                return null;
        }
    }

    public static String getUUId(Category category){
        switch (category){
            case BLOOD_PRESSURE:
                return SharePreferencesUtils.getInstance().getString(BLOOD_PRESSURE+UUID);
            case BLOOD_OXYGEN:
                return SharePreferencesUtils.getInstance().getString(BLOOD_OXYGEN+UUID);
            case BLOOD_SUGAR:
            case CHOLESTEROL:
            case BLOOD_KETONE:
            case URIC_ACID:
                return SharePreferencesUtils.getInstance().getString(BLOOD_FOUR_CATEGORY+UUID);
            case ECG:
                return SharePreferencesUtils.getInstance().getString(ECG+UUID);
            default:
                return null;
        }

    }
    public static String getService(Category category){
        switch (category){
            case BLOOD_PRESSURE:
                return SharePreferencesUtils.getInstance().getString(BLOOD_PRESSURE+SERVICE);
            case BLOOD_OXYGEN:
                return SharePreferencesUtils.getInstance().getString(BLOOD_OXYGEN+SERVICE);
            case BLOOD_SUGAR:
            case CHOLESTEROL:
            case BLOOD_KETONE:
            case URIC_ACID:
                return SharePreferencesUtils.getInstance().getString(BLOOD_FOUR_CATEGORY+SERVICE);
            case ECG:
                return SharePreferencesUtils.getInstance().getString(ECG+SERVICE);
            default:
                return null;
        }

    }
    public static String getCharacteristic(Category category){
        switch (category){
            case BLOOD_PRESSURE:
                return SharePreferencesUtils.getInstance().getString(BLOOD_PRESSURE+CHARACTERISTIC);
            case BLOOD_OXYGEN:
                return SharePreferencesUtils.getInstance().getString(BLOOD_OXYGEN+CHARACTERISTIC);
            case BLOOD_SUGAR:
            case CHOLESTEROL:
            case BLOOD_KETONE:
            case URIC_ACID:
                return SharePreferencesUtils.getInstance().getString(BLOOD_FOUR_CATEGORY+CHARACTERISTIC);
            case ECG:
                return SharePreferencesUtils.getInstance().getString(ECG+CHARACTERISTIC);
            default:
                return null;
        }

    }

    public static boolean putUUId(Category category, String uuid){
        if(uuid==null||uuid.equals("")){
            return false;
        }
        switch (category){
            case BLOOD_PRESSURE:
                return SharePreferencesUtils.getInstance().putString(BLOOD_PRESSURE+UUID,uuid);
            case BLOOD_OXYGEN:
                return SharePreferencesUtils.getInstance().putString(BLOOD_OXYGEN+UUID,uuid);
            case BLOOD_SUGAR:
            case CHOLESTEROL:
            case BLOOD_KETONE:
            case URIC_ACID:
                return SharePreferencesUtils.getInstance().putString(BLOOD_FOUR_CATEGORY+UUID,uuid);
            case ECG:
                return SharePreferencesUtils.getInstance().putString(ECG+UUID,uuid);
            default:
                return false;
        }

    }
    public static boolean putService(Category category,String service){
        switch (category){
            case BLOOD_PRESSURE:
                return SharePreferencesUtils.getInstance().putString(BLOOD_PRESSURE+SERVICE,service);
            case BLOOD_OXYGEN:
                return SharePreferencesUtils.getInstance().putString(BLOOD_OXYGEN+SERVICE,service);
            case BLOOD_SUGAR:
            case CHOLESTEROL:
            case BLOOD_KETONE:
            case URIC_ACID:
                return SharePreferencesUtils.getInstance().putString(BLOOD_FOUR_CATEGORY+SERVICE,service);
            case ECG:
                return SharePreferencesUtils.getInstance().putString(ECG+SERVICE,service);
            default:
                return false;
        }

    }
    public static boolean putCharacteristic(Category category,String characteristic){
        switch (category){
            case BLOOD_PRESSURE:
                return SharePreferencesUtils.getInstance().putString(BLOOD_PRESSURE+CHARACTERISTIC,characteristic);
            case BLOOD_OXYGEN:
                return SharePreferencesUtils.getInstance().putString(BLOOD_OXYGEN+CHARACTERISTIC,characteristic);
            case BLOOD_SUGAR:
            case CHOLESTEROL:
            case BLOOD_KETONE:
            case URIC_ACID:
                return SharePreferencesUtils.getInstance().putString(BLOOD_FOUR_CATEGORY+CHARACTERISTIC,characteristic);
            case ECG:
                return SharePreferencesUtils.getInstance().putString(ECG+CHARACTERISTIC,characteristic);
            default:
                return false;
        }

    }

    //项目类别
    public enum Category  implements Serializable {
        BLOOD_PRESSURE,
        BLOOD_OXYGEN,
        BLOOD_SUGAR,
        CHOLESTEROL,
        BLOOD_KETONE,
        URIC_ACID,
        ECG,
        REPORT,
        ALL,

    }


    public enum UIType  implements Serializable {
        BLOOD_PRESSURE,
        BLOOD_OXYGEN,
        BLOOD_FOUR_CATEGORY,
        ECG,
        CONNECT,
        REPORT,
        ALL,
        MODEL,
        QR_CODE,
    }

    /**
     * 血压数据
     */
    public final static byte[] OPEN_STATIC_PRESS = {(byte) 0xFD, (byte) 0xFD, (byte) 0xFA, (byte) 0xD0, (byte) 0x0D, (byte) 0X0A};
    public final static byte[] CLOSE_STATIC_PRESS = {(byte) 0xFD, (byte) 0xFD, (byte) 0xFA, (byte) 0xD1, (byte) 0x0D, (byte) 0X0A};

    public final static byte[] START_MEASURE = {(byte) 0xFD, (byte) 0xFD, (byte) 0xFA, (byte) 0xD5, (byte) 0x0D, (byte) 0X0A};

    public final static byte[] CLOSE_DEVICE = {(byte) 0xFD, (byte) 0xFD, (byte) 0xFA, (byte) 0xD6, (byte) 0x0D, (byte) 0X0A};

    /**
     * 血糖数据解析
     **/
    //获取试纸类型
    public static String getPaperType(Context context, String string) {
        Resources resources = context.getResources();
        switch (string) {
//            case "01":
//                return "血糖试纸";
//            case "02":
//                return "总胆试纸";
//            case "03":
//                return "尿酸试纸";
//            case "04":
//                return "血酮试纸";
//            case "05":
//                return "血糖CODE";
//            case "06":
//                return "总胆CODE";
//            case "07":
//                return "尿酸CODE";
//            case "08":
//                return "血酮CODE";
//            default:
//                return "测量异常";
//               <string name="blood_sugar_test_paper">血糖试纸</string>
//    <string name="cholesterol_test_paper">总胆试纸</string>
//    <string name="uric_acid_test_paper">尿酸试纸</string>
//    <string name="blood_ketone_test_paper">血酮试纸</string>
//    <string name="blood_sugar_code">血糖CODE</string>
//    <string name="cholesterol_code">总胆CODE</string>
//    <string name="uric_acid_code">尿酸CODE</string>
//    <string name="blood_ketone_code">血酮CODE</string>
//    <string name="measurement_exception">测量异常</string>
            case "01":
                return resources.getString(R.string.blood_sugar_test_paper);
            case "02":
                return resources.getString(R.string.cholesterol_test_paper);
            case "03":
                return resources.getString(R.string.uric_acid_test_paper);
            case "04":
                return resources.getString(R.string.blood_ketone_test_paper);
            case "05":
                return resources.getString(R.string.blood_sugar_code);
            case "06":
                return resources.getString(R.string.cholesterol_code);
            case "07":
                return resources.getString(R.string.uric_acid_code);
            case "08":
                return resources.getString(R.string.blood_ketone_code);
            default:
                return resources.getString(R.string.measurement_exception);
        }
    }

    //获取设备状态
    public static String deviceState(Context context,String string) {
//            <string name="instrument_normal">仪器正常</string>
//    <string name="temperature_too_high">温度过高</string>
//    <string name="temperature_too_low">温度过低</string>
//        switch (string) {
////            case "10":
////                return "仪器正常";
////            case "11":
////                return "温度过高";
////            case "12":
////                return "温度过低";
//
//            default:
//                return null;
//        }
        Resources resources = context.getResources();
        switch (string) {
            case "10":
                return resources.getString(R.string.instrument_normal);
            case "11":
                return resources.getString(R.string.temperature_too_high);
            case "12":
                return resources.getString(R.string.temperature_too_low);
            default:
                return null;
        }
    }

    //获取试纸状态
    public static String paperState(Context context,String string) {
//            <string name="paper_state_01">试纸合格、等待滴血</string>
//    <string name="paper_state_02">试纸过期，请拔出试纸</string>
//    <string name="paper_state_10">CODE 卡更新成功</string>
//    <string name="paper_state_11">CODE 卡校验异常</string>
//    <string name="paper_state_12">0X12:不支持的 CODE</string>
//    <string name="paper_state_exception">试纸异常</string>
//        switch (string) {
//            case "01":
//                return "试纸合格、等待滴血 ";
//            case "02":
//                return "试纸过期，请拔出试纸";
//            case "10":
//                return "CODE 卡更新成功";
//            case "11":
//                return "CODE 卡校验异常";
//            case "12":
//                return "0X12:不支持的 CODE";
//            default:
//                return "试纸异常";
//        }
        Resources resources = context.getResources();
        switch (string) {
            case "01":
                return resources.getString(R.string.paper_state_01);
            case "02":
                return resources.getString(R.string.paper_state_02);
            case "10":
                return resources.getString(R.string.paper_state_10);
            case "11":
                return resources.getString(R.string.paper_state_11);
            case "12":
                return resources.getString(R.string.paper_state_12);
            default:
                return resources.getString(R.string.paper_state_exception);
        }

    }

    //获取血糖状态
    public static String getStatue(Context context,String  string) {
//        switch (string) {
//            case "01":
//                return "正常";
//            case "02":
//                return "偏高";
//            case "03":
//                return "偏低";
//            default:
//                return "测量异常";
//        }
        Resources resources = context.getResources();
        switch (string) {
            case "01":
                return resources.getString(R.string.normal);
            case "02":
                return resources.getString(R.string.high);
            case "03":
                return resources.getString(R.string.low);
            default:
                return resources.getString(R.string.measurement_exception);
        }
    }
}
/**
 * 血糖end
 **/

